import request from '@/utils/request'
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    token: localStorage.getItem('token') || '',
    showLoginModal: false // 添加登录弹窗状态
  }),
  actions: {
    // 控制登录弹窗的方法
    setShowLoginModal(value) {
      this.showLoginModal = value
    },
    // 其他方法...
  }
})
export function login(data) {
  return request({
    url: '/api/user/login',
    method: 'post',
    data
  })
}

export function register(data) {
  return request({
    url: '/api/user/register',
    method: 'post',
    data
  })
}

export function getUserInfo() {
  return request({
    url: '/api/user/info',
    method: 'get'
  })
}

export function logout() {
  return request({
    url: '/api/user/logout',
    method: 'post'
  })
} 